package com.geyue.controller;

import com.geyue.auth.WebSecurityConfig;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * Created by Lyon on 2017/5/15.
 */
@Controller
public class LoginController {

    @RequestMapping("/main.html")
    public String main1(){
        return "main";
    }

    @RequestMapping("/main")
    public String main(){
        return "index";
    }

    @RequestMapping("/login")
    public String login(String username, String password, HttpSession session){

        if("admin".equals(username) && "admin".equals(password)){
            session.setAttribute(WebSecurityConfig.SESSION_KEY,"admin");
            return "redirect:main";
        }

        return "login";
    }

    @RequestMapping("/out")
    public String out(HttpSession session){
        session.removeAttribute(WebSecurityConfig.SESSION_KEY);
        return "redirect:login";
    }
}
